﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Bussiness;

namespace WebApplication.Admin
{
    public partial class BaoCaoTheoNhanVien : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadNhanVien();
                DateTime dt=DateTime.Now;
                datepicker.Text = dt.ToString("dd/MM/yyyy");
               
            }
        }

        protected void lbtnxem_Click(object sender, EventArgs e)
        {
            DateTime dt=Commomcs.convertDate(datepicker.Text);
            string ngay=dt.ToString("dd/MM/yyyy");
            string manv = Dlnhanvien.SelectedValue;
            if (string.IsNullOrEmpty(datepicker.Text))
            {
                RegisterClientScriptBlock("Thông báo", "<script> alert('Chưa chọn ngày')</script>");
                return;
            }
            if (Dlnhanvien.SelectedValue.Equals("0"))
            {
                RegisterClientScriptBlock("Thông báo", "<script> alert('Chưa chọn nhân viên')</script>");
                return;
            }
            var source = new Microsoft.Reporting.WebForms.ReportDataSource("BaoCaoTheoNhanVienTheoNgay", new Baocao.BaoCaoTheoNhanVienTheoNgay().GetBaoCaoTheoNhanVien(dt, ngay,manv));
            ReportViewer1.LocalReport.ReportPath = @"Admin\Baocao\BaoCaotheoNgayTheoNhanVien.rdlc";
            ReportViewer1.LocalReport.DataSources.Clear();
            ReportViewer1.LocalReport.DataSources.Add(source);
            ReportViewer1.LocalReport.Refresh();
            
        }
        public void LoadNhanVien()
        {
            IUnitOfWork iunitfwork = new EFUnitOfWork();
            NHANVIENRepository repositorry = new NHANVIENRepository(new EFRepository<NHANVIEN>(), iunitfwork);
            IQueryable<NHANVIEN> objNhanvien = repositorry.All();
            Dlnhanvien.DataSource = objNhanvien;
            Dlnhanvien.DataValueField = "MANV";
            Dlnhanvien.DataTextField = "TENNV";
            Dlnhanvien.DataBind();
            Dlnhanvien.Items.Insert(0, new ListItem {Text="---Chọn nhân viên---",Value="0" });
        }
    }
}